from django.db import models

# Create your models here.
class User(models.Model):
    user = models.CharField(max_length=100)
    phone=models.CharField(max_length=100)
    password = models.CharField(max_length=100)
    class Meta:
        db_table = 'user'
    def __str__(self):
        return self.user


class Type(models.Model):
    name = models.CharField(max_length=100,verbose_name='图书分类')
    class Meta:
        db_table = 'type'
    def __str__(self):
        return self.name


class House(models.Model):
    name = models.CharField(max_length=100,verbose_name='出版社名称')
    class Meta:
        db_table = 'house'
    def __str__(self):
        return self.name

class Bookname(models.Model):
    name = models.CharField(max_length=100,verbose_name='书架名称')
    class Meta:
        db_table = 'bookname'
    def __str__(self):
        return self.name

class Books(models.Model):
    id=models.AutoField(primary_key=True)
    type= models.ForeignKey(Type,on_delete=models.CASCADE,verbose_name='图书分类')
    house= models.ForeignKey(House,on_delete=models.CASCADE,verbose_name='出版社名称')
    bookname= models.ForeignKey(Bookname,on_delete=models.CASCADE,verbose_name='书架名称')
    img=models.CharField(max_length=100,verbose_name='图书封面')
    name = models.CharField(max_length=100, verbose_name='图书名称')
    auther= models.CharField(max_length=100,verbose_name='作者')
    yi=models.CharField(max_length=100,default='',verbose_name='译者')
    time=models.DateField(verbose_name='出版时间')
    price=models.IntegerField(verbose_name='单价')
    number=models.IntegerField(verbose_name='库存数量')
    class Meta:
        db_table = 'books'
    def __str__(self):
        return self.name

class Detail(models.Model):
    books=models.ForeignKey(Books,on_delete=models.CASCADE,verbose_name='图书名称')
    isDian=models.BooleanField(default=True,verbose_name='是否电子资料')
    isBorrow=models.BooleanField(default=True,verbose_name='是否可借')
    def __str__(self):
        return self.books
    class Meta:
        db_table = 'detail'


class Comment(models.Model):
    user=models.ForeignKey(User,on_delete=models.CASCADE,verbose_name='用户')
    books=models.ForeignKey(Books,on_delete=models.CASCADE,verbose_name='图书名称')
    comment=models.CharField(max_length=100,verbose_name='评论内容')
    time=models.DateTimeField(auto_now=True,verbose_name='评论时间')
    class Meta:
        db_table = 'comment'
    def __str__(self):
        return self.comment






